package com.dys.service.impl;

import com.dys.dao.StudentDao;
import com.dys.dao.impl.StudentDaoImpl;
import com.dys.entity.PageBean;
import com.dys.entity.Student;
import com.dys.service.StudentService;

import java.util.List;

/**
 * @className: com.dys.service.impl.StudentServiceImpl
 * @description: com.dys.service.impl
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/09/25 20:19
 */
public class StudentServiceImpl implements StudentService {
    private final StudentDao studentDao = new StudentDaoImpl();

    @Override
    public PageBean<Student> findByPage(String stuname, String stuage, int currentPage, int pageSize) {
        // 1.查询该页所有数据
        List<Student> list = studentDao.findByPage(stuname, stuage, currentPage, pageSize);
        // 2.查询出有多少条数据
        int totalSize = studentDao.findTotalSize(stuname, stuage);
        // 3.总页数
        int totalPage = totalSize % pageSize == 0 ? totalSize / pageSize : totalSize / pageSize + 1;
        // 4.当前页
        // 5.页大小
        PageBean<Student> pageBean = new PageBean<>(list, totalSize, totalPage, currentPage, pageSize);
        return pageBean;
    }
}
